package com.t.bricks.bussiness.db.dao.stock.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.t.bricks.bussiness.db.dao.stock.StockDao;
import com.t.bricks.bussiness.db.entity.stock.Stock;
import com.t.bricks.bussiness.db.mapper.stock.StockMapper;
import com.t.bricks.model.Log;
import com.t.bricks.model.MsgEmity;

@Repository
public class StockDaoImpl implements StockDao {
	
	@Autowired
	private StockMapper stockMapper;

	//---------------------------- 自动生成代码结束 ----------------------------//

	/**
	 * 根据物品编号/仓库编号/批次取分组数据
	 * @param iWarehouse 启用仓库分组
	 * @param iBatch 启用批次分组
	 * @param sGoodsId 物品编号条件
	 * @param sWarehouseId 仓库编号条件
	 * @param sBatch 批次条件
	 * @param dMakeDateSt 生产日期范围-起
	 * @param dMakeDateEd 生产日期范围-止
	 * @return MsgEmity
	 */
	@Override
	public MsgEmity findByGroup(Integer iWarehouse, Integer iBatch,
			String sGoodsId, String sWarehouseId, String sBatch,
			Date dMakeDateSt, Date dMakeDateEd) {
		List<Stock> list = null;
		try {
			list = stockMapper.findByGroup(iWarehouse, iBatch, sGoodsId,
					sWarehouseId, sBatch, dMakeDateSt, dMakeDateEd);
			if (null == list) {
				Log.error("查询分组数据发生异常,执行的返回值为:null,预期值不应为null");
				return new MsgEmity(false, "查询操作失败！", 7001);
			}
		} catch (Exception e) {
			Log.error("查询分组数据发生异常:", e.getMessage());
			return new MsgEmity(false, "查询请求失败，请查看异常日志！", 7002);
		}
		
		return new MsgEmity(true, "查询成功！", list);
	}

	/**
	 * 检查当前库存量
	 * @param sGoodsId 物品编号条件
	 * @param sWarehouseId 仓库编号条件
	 * @param sBatch 批次条件
	 * @return MsgEmity
	 */
	@Override
	public MsgEmity findQuantity(String sGoodsId, String sWarehouseId, String sBatch) {
		try {
			int iCount = stockMapper.findQuantity(sGoodsId, sWarehouseId, sBatch);
			return new MsgEmity(true, "查询成功！", iCount);
		} catch (Exception e) {
			Log.error("查询当前库存量发生异常:", e.getMessage());
			return new MsgEmity(false, "查询请求失败，请查看异常日志！", 7001);
		}
	}
	
}
